<template>
  <view class="container">
    <view class="back">
      <image src="/static/img/icon11.png" mode="widthFix"></image>
    </view>
    <view class="center-layout">
      <text class="title">个人中心</text>
      <view class="wrap">
        <view class="per-wrap" @tap="handleLink('/pages/personalInfor/personalInfor')">
          <view class="picture">
            <image :src="userPic" mode="widthFix"></image>
          </view>
          <view class="text">
            <text class="h2">{{ userNickname }}</text>
            <view class="desc">
              {{ enterprise }}
            </view>
          </view>

          <view class="set">
            <image src="/static/img/icon10.png" mode=""></image>
          </view>
        </view>
        <view class="img_list" style="display: none">
          <img src="/static/img/xunzhang.png" />
          <img src="/static/img/xunzhang2.png" />
        </view>
        <tag-components />
        <view class="ul">
          <view
            class="li"
            @tap="
              handleLink(
                `/pages/pointRecord/pointRecord`
              )
            "
          >
            <text class="b">{{ userinfo.userPoint || 0 }}</text>
            <text class="p">积分</text>
          </view>
          <!-- <view class="li">
            <text class="b">{{ userinfo.userScore }}</text>
            <text class="p">贡献值</text>
          </view> -->
          <view
            class="li"
            @tap="
              handleLink(
                `/pages/pointRecord/pointRecord`
              )
            "
          >
            <text class="b">{{ userinfo.userVit || 0 }}</text>
            <text class="p">活力值</text>
          </view>
        </view>
      </view>
    </view>

    <view class="list-menu tab-botton">
      <view class="ul">
        <view class="li" v-for="(item,v) in isShowsList" :key="v" @tap="handleLink1(item)">
          <view class="files">
            <image class="icon" :src="item.icon"></image>
            <text>{{item.name}}</text>
          </view>
          <image class="more" src="/static/img/icon1.png"></image>
        </view>
      </view>
    </view>
    <tabs-box></tabs-box>
  </view>
</template>

<script>
import { mapState, mapMutations } from 'vuex'
import { gpUserInfo, getgpUsercom } from '@/common/request.js'
import {myRouter} from './js/page'
import tagComponents from './components/tag-con'
export default {
  data() {
    return {
      userNickname: '',
      userPic: '/static/img/logob.png',
      enterprise: '',
      userinfo: [],
      myRouter,
    }
  },
  components:{
    tagComponents
  },
  computed: {
    ...mapState(['hasLogin', 'userInfo', 'token']),
    isShowsList(){
      return myRouter.filter(item=>item.isShow!==-2)
    },

  },
  onLoad() {
    const token = uni.getStorageSync('token')
    if (!token) {
      uni.navigateTo({
        url: '../login/login',
      })
      return
    }
  },
  onShow() {
    // #ifdef H5
    console.log('分享')
    this.$wxSetShare()
    // #endif
    if (!uni.getStorageSync('token')) {
      uni.navigateTo({
        url: '../login/login',
      })
      return
    }
    const res = this.$store.state.userInfo
      if (res) {
        this.userNickname = res&& res.userNickname
        this.userPic = res.userPic || '/static/img/logob.png'
        this.userinfo = res
        //userType为2表示法人登录
        if(res.userType===2){
          myRouter[0].isShow = 2
        }
      }

    getgpUsercom().then((res) => {
      if (res.success) {
        this.enterprise = res.result && res.result.usercomName
      }
    })
  },

  methods: {
    handleLink(link) {
      uni.navigateTo({
        url: link,
      })
    },
    ...mapMutations(['logout']),
    loginout() {
      this.logout()
      this.$api.msg('退出成功!')
      uni.removeStorageSync('categoryName-vuedraggable-draggableValue');
      uni.removeStorageSync('update-close-next');
      setTimeout(() => {
        uni.navigateTo({
          url: '../index/index',
        })
      }, 1000)
    },
    handleLink1(item){
      if(item.url){
        this.handleLink(item.url)
      }
      else if(item.isShow==='out'){
        this.loginout()
      }
    }
  },
}
</script>

<style lang="stylus" scoped>
@import "./css/index.styl"
.atext{
  text{
    padding:20rpx 20rpx;
    display: inline-block;
  }
}
</style>
